#include <stdlib.h>
#include <iostream>
#include <string>
#include <boost/bind.hpp>
#include <boost/thread.hpp>
#include <boost/date_time.hpp>
     
using namespace std;

class trd
{
		boost::thread workerThread;
		boost::thread workerThread2;
		boost::thread workerThread3;
		boost::thread workerThread4;
	public:
	trd():	workerThread(boost::bind(&trd::workerFunc,this)),
		workerThread2(boost::bind(&trd::video,this,"animGar.mp4")),
		workerThread3(boost::bind(&trd::sound,this,"cartoon.mp3"))
		workerThread4(boost::bind(&trd::loop,this))
	{
		

		std::cout << "main: waiting for thread" << std::endl;

		workerThread.join();
		workerThread2.join();
		workerThread3.join();
	}

	void workerFunc()
	{
		boost::posix_time::seconds workTime(5);

		std::cout << "Worker: running" << std::endl;

		// Pretend to do something useful...
		boost::this_thread::sleep(workTime);

		std::cout << "Worker: finished" << std::endl;
		workerThread2.detach();
		workerThread3.detach();
	}

	void video(string v)
	{
		v = "ffplay medias/" + v  + " >> video.log  2>&1";
		int i=system (v.c_str());
		std::cout << "process["<< i << "] finished" << std::endl;
	}

	void sound(string s)
	{
		s = "ffplay medias/" + s + " >> video.log  2>&1";
		int i=system (s.c_str());
		std::cout << "process["<< i << "] finished" << std::endl;
	}

	void loop()
	{
		while(1)
		{
			std::cout << "crazy thread!" << std::endl;
		}
	}
};

int main(int argc, char* argv[])
{
	std::cout << "main: startup" << std::endl;
	trd t;
	std::cout << "main: done" << std::endl;
	return 0;
}
